package com.smart.web.controller.user.bucket;


import com.smart.common.core.domain.R;
import com.smart.common.utils.DateUtils;
import com.smart.common.utils.modbus.ModbusUtil;
import com.smart.system.service.IBucketCapacityRecordService;
import com.smart.system.service.IBucketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/uplink")
public class UplinkController {

    @Autowired
    private IBucketService bucketService;

    @Autowired
    private IBucketCapacityRecordService bucketCapacityRecordService;

    @GetMapping("/up")
    public R up(HttpServletRequest request, String data){
//        Map<String, String[]> parameterMap = request.getParameterMap();
//        for (String s : parameterMap.keySet()) {
//            String[] strings = parameterMap.get(s);
//            for (String string : strings) {
//                System.err.println(s + ":" + string);
//            }
//        }
        ModbusUtil.Modbus analysis = ModbusUtil.analysis(data);
        return R.ok(bucketService.uplink(analysis));
    }

    @GetMapping("/test")
    public R test(){
        Map<String, Object> stringObjectMap = bucketCapacityRecordService.get(DateUtils.getStartTime(), DateUtils.getEndTime(),null);
        return R.ok(stringObjectMap);
    }
}
